//
//  HLUIHelper.m
//  YueYue
//
//  Created by hulu001 on 2023/5/17.
//

#import "HLUIHelper.h"
#import <NIMSDK/NIMSDK.h>
#import <YYText/YYText.h>
#import "HLCallTool.h"
#import "HLUserOptionRequest.h"
#import "HLLoginOptionRequest.h"
#import "HLWebViewController.h"
#import "HLTabBarViewController.h"
#import "HLLoginViewController.h"
#import "HLLoginInfoViewController.h"
#import "HLNavigationController.h"
#import "HLMessageSessionViewController.h"
#import "HLEditInfoViewController.h"
#import "HLTableViewController.h"
#import "HLRtcExitView.h"
#import "HLShareContainerView.h"

NSString *const HLSelectedThemeIdentifier = @"selectedThemeIdentifier";
NSString *const HLMustAgreeIdentifier = @"MustAgreeIdentifier";
NSString *const HLSquareCommentTipIdentifier = @"squareCommentTipIdentifier";
NSString *const HLUserDetailScrollDidChangeNotification = @"UserDetailScrollDidChangeNotification";
NSString *const HLUserFollowDidChangeNotification = @"UserFollowDidChangeNotification";
NSString *const HLVideoViewDidChangeNotification = @"VideoViewDidChangeNotification";
NSString *const HLUpdateStickTopNotification = @"UpdateStickTopNotification";
NSString *const HLScreenChangedNotification = @"ScreenChangedNotification";
NSString *const HLListPageSize = @"20";
NSString *const HLUserPhotoWallCount = @"6";
NSInteger const HLCommonTagA = 1243;
NSInteger const HLCommonTagB = 3424;
NSInteger const HLCommonSmsSecondCount = 60;

#if DEBUG
NSString *const HLH5IncomeUrl =  @"http://payh5.yueyueworld.com:8002/woyu/h5/rechargeCenter/index.html";
NSString *const HLH5MemberCenterUrl = @"http://payh5.yueyueworld.com:8002/woyu/h5/memberCenter/index.html";
NSString *const HLH5MemberCenterRecordUrl = @"http://payh5.yueyueworld.com:8002/woyu/h5/memberCenter/record.html";
NSString *const HLH5ExchangeUrl = @"http://payh5.yueyueworld.com:8002/woyu/h5/taskSign/index.html";

// 未使用
NSString *const HLH5InvitationUrl = @"http://payh5.yueyueworld.com:8002/yuejiao/h5/invite/domesticInvite.html";
NSString *const HLH5GuardianUrl = @"http://payh5.yueyueworld.com:8002/platformH5/myGuard/index.html";
NSString *const HLH5CertSettingUrl = @"http://payh5.yueyueworld.com:8002/grade/setPrice.html";
NSString *const HLH5CertSettingVideoUrl = @"http://payh5.yueyueworld.com:8002/grade/videoPrice.html";
NSString *const HLH5QRCodeCustomerServiceUrl = @"http://payh5.yueyueworld.com:8002/QRCode/customerService.html";
NSString *const HLH5QRCodeNoticeUrl = @"http://payh5.yueyueworld.com:8002/QRCode/notice.html";

// 自定义
NSString *const HLH5ProtocolUserUrl = @"https://juejin.cn/post/7292750227509772328";
NSString *const HLH5ProtocolPrivacyUrl = @"https://juejin.cn/post/7292750227509624872";

//NSString *const HLH5IncomeUrl =  @"https://h5.yueyueworld.com/yuemei/rechargeCenter/index.html";
//NSString *const HLH5MemberCenterUrl = @"https://h5.yueyueworld.com/yuemei/memberCenter/index.html";
//NSString *const HLH5MemberCenterRecordUrl = @" https://shwan.cc/h5/memberCenter/record.html";
//NSString *const HLH5ExchangeUrl = @"https://shwan.cc/h5/taskSign/index.html";
//
//NSString *const HLH5InvitationUrl = @"https://kehoo.cc/h5/invite/domesticInvite.html";
//NSString *const HLH5GuardianUrl = @"http://payh5.yueyueworld.com:8002/platformH5/myGuard/index.html";
//
//NSString *const HLH5CertSettingUrl = @"http://payh5.yueyueworld.com:8002/grade/setPrice.html";
//NSString *const HLH5CertSettingVideoUrl = @"http://payh5.yueyueworld.com:8002/grade/videoPrice.html";
//NSString *const HLH5QRCodeCustomerServiceUrl = @"http://payh5.yueyueworld.com:8002/QRCode/customerService.html";
//NSString *const HLH5QRCodeNoticeUrl = @"http://payh5.yueyueworld.com:8002/QRCode/notice.html";
//NSString *const HLH5ProtocolUserUrl = @"https://juejin.cn/post/7292750227509772328";
//NSString *const HLH5ProtocolPrivacyUrl = @"https://juejin.cn/post/7292750227509624872";

#else

NSString *const HLH5IncomeUrl =  @"https://h5.yueyueworld.com/yuemei/rechargeCenter/index.html";
NSString *const HLH5MemberCenterUrl = @"https://h5.yueyueworld.com/yuemei/memberCenter/index.html";
NSString *const HLH5MemberCenterRecordUrl = @" https://shwan.cc/h5/memberCenter/record.html";
NSString *const HLH5ExchangeUrl = @"https://shwan.cc/h5/taskSign/index.html";

NSString *const HLH5InvitationUrl = @"https://kehoo.cc/h5/invite/domesticInvite.html";
NSString *const HLH5GuardianUrl = @"http://payh5.yueyueworld.com:8002/platformH5/myGuard/index.html";

NSString *const HLH5CertSettingUrl = @"http://payh5.yueyueworld.com:8002/grade/setPrice.html";
NSString *const HLH5CertSettingVideoUrl = @"http://payh5.yueyueworld.com:8002/grade/videoPrice.html";
NSString *const HLH5QRCodeCustomerServiceUrl = @"http://payh5.yueyueworld.com:8002/QRCode/customerService.html";
NSString *const HLH5QRCodeNoticeUrl = @"http://payh5.yueyueworld.com:8002/QRCode/notice.html";
NSString *const HLH5ProtocolUserUrl = @"https://juejin.cn/post/7292750227509772328";
NSString *const HLH5ProtocolPrivacyUrl = @"https://juejin.cn/post/7292750227509624872";
#endif

@implementation HLUIHelper

+ (UIImage *)avatarPlaceholder
{
    if ([HLHelper isFemale]) {
        return [UIImage imageNamed:@"avatar_male_placeholder"];
    }
    
    return [UIImage imageNamed:@"avatar_famale_placeholder"];
}

+ (UIImage *)imagePlaceholder
{
    return [UIImage imageNamed:@"image_placeholder"];
}


+ (UIImage *)avatarBigPlaceholder
{
    if ([HLHelper isFemale]) {
        return [UIImage imageNamed:@"avatar_male_big_placeholder"];
    }
    
    return [UIImage imageNamed:@"avatar_famale_big_placeholder"];
}

// 真人标签
+ (QMUIButton *)realIconView
{
    QMUIButton *_realIcon = [[QMUIButton alloc] init];
    [_realIcon setImage:UIImageMake(@"home_cell_real") forState:UIControlStateNormal];
    return _realIcon;
}

// vip标签
+ (QMUIButton *)vipIconView
{
    QMUIButton *_vipIcon = [[QMUIButton alloc] init];
    [_vipIcon setImage:UIImageMake(@"home_cell_vip") forState:UIControlStateNormal];
    return _vipIcon;
}

+ (QMUIButton *)sexAgeIconViewWithSex:(NSString *)sex age:(NSString *)age
{
    QMUIButton *_sexView = [[QMUIButton alloc] init];
    if ([sex isEqualToString:@"1"]){
        [_sexView setImage:UIImageMake(@"home_cell_male") forState:UIControlStateNormal];
        [_sexView setBackgroundColor:HLMainColor];
    } else {
        [_sexView setImage:UIImageMake(@"home_cell_female") forState:UIControlStateNormal];
        [_sexView setBackgroundColor:HLAideColor5];
    }

    [_sexView setTitle:age forState:UIControlStateNormal];
    [_sexView setTitleColor:UIColorWhite forState:UIControlStateNormal];
    [_sexView.titleLabel setFont:UIFontMediumMake(10)];
   
    _sexView.imagePosition = QMUIButtonImagePositionLeft;
    _sexView.spacingBetweenImageAndTitle = 0;
    _sexView.contentEdgeInsets = UIEdgeInsetsMake(2, 2, 2, 4);
    _sexView.cornerRadius = 8;
    _sexView.userInteractionEnabled = NO;
    return _sexView;
}

+ (QMUIButton *)iconIDViewWithId:(NSString *)eid
{
    QMUIButton *_eidView = [[QMUIButton alloc] init];
    [_eidView setImage:UIImageMake(@"user_detail_id") forState:UIControlStateNormal];

    [_eidView setTitle:eid forState:UIControlStateNormal];
    [_eidView setTitleColor:HLTextColor2 forState:UIControlStateNormal];
    [_eidView.titleLabel setFont:UIFontMake(12)];
   
    _eidView.imagePosition = QMUIButtonImagePositionLeft;
    _eidView.spacingBetweenImageAndTitle = 4;
    return _eidView;
}

// 财富标签
+ (QMUIButton *)wealthIconViewWithLevel:(NSString *)level
{
    QMUIButton *_wealthIcon = [[QMUIButton alloc] init];
    [_wealthIcon setBackgroundImage:UIImageMake(@"home_cell_wealth_1") forState:UIControlStateNormal];
    [_wealthIcon setTitle:level forState:UIControlStateNormal];
    [_wealthIcon setTitleColor:UIColorWhite forState:UIControlStateNormal];
    [_wealthIcon.titleLabel setFont:UIFontMake(11)];
    _wealthIcon.contentEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 4);
    return _wealthIcon;
}

+ (QMUIButton *)sexIconViewWithSex:(NSString *)sex
{
    QMUIButton *_sexIcon = [[QMUIButton alloc] init];
    if ([sex isEqualToString:@"1"]){
        [_sexIcon setImage:UIImageMake(@"home_cell_male") forState:UIControlStateNormal];
    } else {
        [_sexIcon setImage:UIImageMake(@"home_cell_female") forState:UIControlStateNormal];
    }
    return _sexIcon;
}

+ (QMUIButton *)sexIconViewWithSex:(NSString *)sex age:(NSString *)age
{
    QMUIButton *_sexIcon = [[QMUIButton alloc] init];
    if ([sex isEqualToString:@"1"]){
        [_sexIcon setImage:UIImageMake(@"home_cell_male") forState:UIControlStateNormal];
    } else {
        [_sexIcon setImage:UIImageMake(@"home_cell_female") forState:UIControlStateNormal];
    }
    [_sexIcon setTitle:age forState:UIControlStateNormal];
    [_sexIcon setTitleColor:HLTextColor1 forState:UIControlStateNormal];
    [_sexIcon.titleLabel setFont:UIFontMediumMake(10)];
    _sexIcon.imagePosition = QMUIButtonImagePositionLeft;
    _sexIcon.spacingBetweenImageAndTitle = 2;
    return _sexIcon;
}

+ (void)showAlertWithContent:(NSString *)content
                  callBack:(HLCommonCallbackBoolBlock)callback
{
    [self showAlertWithTitle:@"提示" content:content leftButtonTitle:@"取消" rightButtonTitle:@"确认" callBack:callback];
}

+ (void)showAlertWithTitle:(NSString *)title
                   content:(NSString *)content
                  callBack:(HLCommonCallbackBoolBlock)callback
{
    [self showAlertWithTitle:title content:content leftButtonTitle:@"取消" rightButtonTitle:@"确认" callBack:callback];
}

+ (void)showAlertWithTitle:(NSString *)title
                   content:(NSString *)content
           leftButtonTitle:(NSString *)left
          rightButtonTitle:(NSString *)right
                  callBack:(HLCommonCallbackBoolBlock)callback
{
    
    
    QMUIAlertAction *actionLeft = [QMUIAlertAction actionWithTitle:left style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
        if (callback){
            callback(NO);
        }
    }];

    
    QMUIAlertAction *actionRight = [QMUIAlertAction actionWithTitle:right style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
        if (callback){
            callback(YES);
        }
    }];
    
    QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:title message:content preferredStyle:QMUIAlertControllerStyleAlert];
    alertController.alertContentMargin = UIEdgeInsetsMake(12, 0, 12, 0);
    alertController.alertTitleMessageSpacing = 12;
    alertController.alertTitleAttributes = @{NSForegroundColorAttributeName:HLTextColor1,NSFontAttributeName:UIFontMediumMake(17)};
    alertController.alertMessageAttributes = @{NSForegroundColorAttributeName:HLTextColor2,NSFontAttributeName:UIFontMediumMake(13)};
    alertController.alertButtonAttributes = @{NSForegroundColorAttributeName:HLTextColor2,NSFontAttributeName:UIFontMake(16)};
    [alertController addAction:actionRight];
    [alertController addAction:actionLeft];
    [alertController showWithAnimated:YES];
}

+ (void)showAlertInfoWithTitle:(NSString *)title content:(NSString *)content
{
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 0)];
    contentView.backgroundColor = UIColorWhite;
    contentView.layer.cornerRadius = 6;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = UIFontMediumMake(16);
    titleLabel.textColor = HLTextColor1;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.numberOfLines = 0;
    titleLabel.text = title;
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.right.mas_equalTo(-16);
    }];
    
    UILabel *contentLabel = [[UILabel alloc] init];
    contentLabel.font = UIFontMake(14);
    contentLabel.textColor = HLTextColor1;
    contentLabel.textAlignment = NSTextAlignmentCenter;
    contentLabel.numberOfLines = 0;
    contentLabel.qmui_lineHeight = 24;
    contentLabel.text = content;
    [contentView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(18);
        make.left.mas_equalTo(16);
        make.right.bottom.mas_equalTo(-16);
    }];
    
    contentView.qmui_height = [contentView systemLayoutSizeFittingSize:CGSizeMake(300, 0) withHorizontalFittingPriority:UILayoutPriorityRequired verticalFittingPriority:UILayoutPriorityFittingSizeLevel].height;;
    QMUIModalPresentationViewController *modalViewController = [[QMUIModalPresentationViewController alloc] init];
    modalViewController.contentView = contentView;
    [modalViewController showWithAnimated:YES completion:nil];
}

+ (void)chatWithUserId:(NSString *)userId
            controller:(UIViewController *)controller
{
    HLMessageSessionViewController *sessionVC = [[HLMessageSessionViewController alloc] initWithSession:[NIMSession session:userId type:NIMSessionTypeP2P]];
    sessionVC.maleClient = @"Platform";
    [controller.navigationController pushViewController:sessionVC animated:YES];
}

+ (void)h5WithURL:(NSString *)urlString controller:(UIViewController *)controller
{
    HLWebViewController *webVC = [[HLWebViewController alloc] initWithUrl:[HLHelper addTokenParamWithBaesURL:urlString] hiddenNav:NO];
    [controller.navigationController pushViewController:webVC animated:YES];
}

+ (void)callWithUser:(HLUserInfoModel *)user
{
    if ([HLRunTime shareInstance].isFood) {
        [QMUITips showWithText:@"对方已离线"];
        return;
    }
    
    [[HLCallTool shareInstance] callUser:user OnVC:[QMUIHelper visibleViewController]];
}

+ (void)greetWithParam:(NSDictionary *)params callBack:(HLCommonCallbackBoolStringBlock)callback
{
    HLUserOptionRequest *optionRequest = [[HLUserOptionRequest alloc] initWithType:HLUserOptionTypeChatUp params:params];
    [optionRequest startWithCompletionBlockWithSuccess:^(__kindof HLUserOptionRequest * _Nonnull request) {
        if(callback)callback(request.isSuccess, request.message);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        if(callback)callback(NO, @"");
    }];
}

+ (void)showRequiredLabelWithView:(UIView *)view
{
    UILabel *textWarningLabel = [[UILabel alloc] qmui_initWithFont:UIFontMake(22) textColor:UIColorRed];
    textWarningLabel.text = @"*";
    [view.superview addSubview:textWarningLabel];
    [textWarningLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_right).offset(4);
        make.centerY.equalTo(view);
    }];
}

+ (void)blackWithUserId:(NSString *)userID
                  black:(BOOL)isBlack
               callback:(HLCommonCallbackBoolBlock)callback
{
    HLUserOptionType type = HLUserOptionTypeBlack;
    NSDictionary *params = @{@"friendId": userID,@"type": @"1"};
    if (isBlack){
        type = HLUserOptionTypeUnBlack;
        params = @{@"friendId": userID,@"type": @"2"};
    }
    HLUserOptionRequest *optionRequest = [[HLUserOptionRequest alloc] initWithType:type params:params];
    
    NSString *blackContent = @"拉黑该用户";
    if (isBlack){
        blackContent = @"将该用户移出黑名单";
    }
    
    
    YTKRequestCompletionBlock successBlock = ^(__kindof HLUserOptionRequest * _Nonnull request) {
     
        if (request.isSuccess){
            if (type == HLUserOptionTypeBlack){
                [QMUITips showWithText:@"用户已被加入黑名单"];
            } else {
                [QMUITips showWithText:@"用户已被移出黑名单"];
            }
            callback(YES);
        } else {
            callback(NO);
        }
        
    };
    
    [HLUIHelper showAlertWithContent:blackContent callBack:^(BOOL isTure) {
        if (isTure){
            [optionRequest startWithCompletionBlockWithSuccess:successBlock failure:nil];
        }
    }];
}

+ (void)followWithUserId:(NSString *)userID
                  follow:(BOOL)isFollow
                callback:(HLCommonCallbackBoolBlock)callback
{
    HLUserOptionType type = HLUserOptionTypeFollow;
    NSDictionary *params = @{@"followMemberId": userID};
    if (isFollow){
        type = HLUserOptionTypeUnFollow;
    }
    HLUserOptionRequest *optionRequest = [[HLUserOptionRequest alloc] initWithType:type params:params];
    
    YTKRequestCompletionBlock successBlock = ^(__kindof HLUserOptionRequest * _Nonnull request) {
        if (request.isSuccess){
            if (type == HLUserOptionTypeFollow){
                [QMUITips showWithText:@"关注成功"];
            } else {
                [QMUITips showWithText:@"已取消关注"];
            }
            [[NSNotificationCenter defaultCenter] postNotificationName:HLUserFollowDidChangeNotification object:@{@"type":@(type), @"user":userID}];
            callback(YES);
        }else {
            callback(NO);
        }
    };
    
    if (type ==  HLUserOptionTypeUnFollow){
        [HLRtcExitView showWithTitle:@"温馨提示" Content:@"确认取消关注此用户"  LeftButtonTitle:@"确定" RightButtonTitle:@"取消" Callback:^(BOOL confirm) {
            if (confirm){
                [optionRequest startWithCompletionBlockWithSuccess:successBlock failure:nil];
            }
        }];
    } else {
        [optionRequest startWithCompletionBlockWithSuccess:successBlock failure:nil];
    }
}

+ (UIWindow *)keyWindow
{
    return [UIApplication sharedApplication].delegate.window;
}

+ (void)showSessionViewControllerWithSession:(NIMSession *)session
{
    HLMessageSessionViewController *sessionVC = [[HLMessageSessionViewController alloc] initWithSession:session];
    sessionVC.maleClient = @"Platform";
    [[QMUIHelper visibleViewController].navigationController pushViewController:sessionVC animated:YES];
}

+ (void)setRootTabBar {
    HLTabBarViewController *tabVC = [[HLTabBarViewController alloc] init];
    [self keyWindow].rootViewController = tabVC;
}

+ (void)setRootLogin {
    HLLoginViewController *loginVC = [[HLLoginViewController alloc] init];
    HLNavigationController *navigationVC = [[HLNavigationController alloc] initWithRootViewController:loginVC];
    [self keyWindow].rootViewController = navigationVC;
}

+ (void)setRootInfo {
    HLLoginInfoViewController *loginInfoVC = [[HLLoginInfoViewController alloc] init];
    HLNavigationController *navigationVC = [[HLNavigationController alloc] initWithRootViewController:loginInfoVC];
    [self keyWindow].rootViewController = navigationVC;
}

+ (void)setRootLaunch {
    [self keyWindow].rootViewController =  [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil] instantiateInitialViewController];
}

+ (void)loginWithParams:(NSDictionary *)params
{
    HLLoginOptionType type = HLLoginOptionTypeLogin;
//    if ([params[@"loginType"] isEqualToString:@"4"]){
//        type = HLLoginOptionTypeWechat;
//    }
    HLLoginOptionRequest *loginOptionRequest = [[HLLoginOptionRequest alloc] initWithType:type params:params];
    [loginOptionRequest startWithCompletionBlockWithSuccess:^(__kindof HLLoginOptionRequest * _Nonnull request) {
        if (request.isSuccess){
            HLLoginModel *login = [HLLoginModel mj_objectWithKeyValues:request.result[@"data"]];
            [login syncDataKeychain];
            [[HLRunTime shareInstance] loginWithData:login];
        }
    } failure:nil];
}


+ (HLTableViewController *)tab_controller
{
    HLTableViewController *tabController = (HLTableViewController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    return tabController;
}


+ (void)jumpWithKey:(NSString *)key param:(NSString *)param
{
    UINavigationController *navigationController = [QMUIHelper visibleViewController].navigationController;
    [navigationController popViewControllerAnimated:NO];
    if ([key isEqualToString:@"first_chatUp"]){
        [self.tab_controller cyl_popSelectTabBarChildViewControllerAtIndex:0];
    } else if ([key isEqualToString:@"daily_chatUp"]) {
        [self.tab_controller cyl_popSelectTabBarChildViewControllerAtIndex:0];
    } else if ([key isEqualToString:@"daily_gift"]) {
        [self.tab_controller cyl_popSelectTabBarChildViewControllerAtIndex:2];
    } else if ([key isEqualToString:@"daily_share"]) {
        [HLShareContainerView showWithCallback:^(NSString *item) {
            
        }];
    } else if ([key isEqualToString:@"daily_video"]) {
        [self.tab_controller cyl_popSelectTabBarChildViewControllerAtIndex:2];
    } else if ([key isEqualToString:@"first_gift"]) {
        [self.tab_controller cyl_popSelectTabBarChildViewControllerAtIndex:2];
    } else if ([key isEqualToString:@"first_video"]) {
        [self.tab_controller cyl_popSelectTabBarChildViewControllerAtIndex:2];
    } else if ([key isEqualToString:@"rich_photo_wall"] || [key isEqualToString:@"upload_avatar"] || [key isEqualToString:@"add_signature"]) {
        HLEditInfoViewController *editInfo = [[HLEditInfoViewController alloc] initWithModel:HLRunTime.shareInstance.mine callback:^(NSString *str) {
        }];
        [navigationController pushViewController:editInfo animated:YES];
    } else if ([key isEqualToString:@"im_chat"]) {
        [self.tab_controller cyl_popSelectTabBarChildViewControllerAtIndex:2];
    } else if ([key isEqualToString:@"VIP"]) {
        HLWebViewController *webVC = [[HLWebViewController alloc] initWithUrl:[HLHelper addTokenParamWithBaesURL:HLH5MemberCenterUrl] hiddenNav:NO];
        [navigationController pushViewController:webVC animated:YES];
    } else if ([key isEqualToString:@"Recharge"]) {
        HLWebViewController *webVC = [[HLWebViewController alloc] initWithUrl:[HLHelper addTokenParamWithBaesURL:HLH5IncomeUrl] hiddenNav:NO];
        [navigationController pushViewController:webVC animated:YES];
    } else if ([key isEqualToString:@"PayH5"]) {
        //[self pushH5RchargeWithController:self.getCurrentTopVC];
    } else if ([key isEqualToString:@"ShareActivity"]) {
        HLWebViewController *webVC = [[HLWebViewController alloc] initWithUrl:[HLHelper addTokenParamWithBaesURL:HLH5InvitationUrl] hiddenNav:NO];
        [navigationController pushViewController:webVC animated:YES];
    } else if ([key isEqualToString:@"home_page"] || [key isEqualToString:@"Home"]) {
        [navigationController popToRootViewControllerAnimated:NO];
        [self.tab_controller cyl_popSelectTabBarChildViewControllerAtIndex:0];
    } else if ([key isEqualToString:@"Me"]) {
        // 个人中心
        [navigationController popToRootViewControllerAnimated:NO];
        [self.tab_controller cyl_popSelectTabBarChildViewControllerAtIndex:3];
    } else if ([key isEqualToString:@"OutLink"]) {
        HLWebViewController *webVC = [[HLWebViewController alloc] initWithUrl:param hiddenNav:NO];
        [navigationController pushViewController:webVC animated:YES];
    } else if ([key isEqualToString:@"OutLinkWithToken"]) {
        HLWebViewController *webVC = [[HLWebViewController alloc] initWithUrl:[HLHelper addTokenParamWithBaesURL:param] hiddenNav:NO];
        [navigationController pushViewController:webVC animated:YES];
    } else if ([key isEqualToString:@"Browser"]) {
        // 外部浏览器
        [UIApplication.sharedApplication openURL:[NSURL URLWithString:param] options:@{} completionHandler:nil];
    } else if ([key isEqualToString:@"BrowserWithToken"]) {
        NSString *url = [HLHelper addTokenParamWithBaesURL:param];
        [UIApplication.sharedApplication openURL:[NSURL URLWithString:url] options:@{} completionHandler:nil];
    }
}


+ (void)getUserInfoWithSessionId:(NSString *)sessionId
                        callback:(HLCommonCallback)callback
{
    NIMUser *user = [NIMSDK.sharedSDK.userManager userInfo:sessionId];
    if (user.userInfo.nickName) {
        callback(user);
        return;
    }
    // 云信获取用户信息
    [NIMSDK.sharedSDK.userManager fetchUserInfos:@[sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
        callback(users.firstObject);
    }];
}

+ (BRPickerStyle *)pickerStyle
{
    BRPickerStyle *_customStyle = [[BRPickerStyle alloc]init];
    _customStyle.pickerTextColor = HLMainColor;
    _customStyle.separatorColor = HLLineColor;
    return _customStyle;
}

+ (void)showAlertMustAgreeInfo
{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    
    if ([userDefault boolForKey:HLMustAgreeIdentifier]){
        return;
    }
    
    QMUIModalPresentationViewController *modalViewController = [[QMUIModalPresentationViewController alloc] init];
    modalViewController.modal = YES;
    
    
    CGFloat width = SCREEN_WIDTH - 80;
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 410)];
    contentView.backgroundColor = UIColorWhite;
    contentView.layer.cornerRadius = 8;
    contentView.layer.masksToBounds = YES;
    
    
    
    UILabel *titleLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(20) textColor:HLTextColor1];
    titleLabel.text = @"欢迎来到越轻盈！";
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(24);
    }];
    
    UIImageView *iconView = [[UIImageView alloc] initWithImage:UIImageMake(@"must_agree_icon")];
    [contentView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16);
        make.right.mas_equalTo(-12);
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = HLLineColor;
    [contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(iconView.mas_bottom).offset(2);
    }];
    
    
    YYLabel *agreeLabel = [[YYLabel alloc] init];
    agreeLabel.font = UIFontMediumMake(12);
    agreeLabel.textColor = HLTextColor1;
    agreeLabel.numberOfLines = 3;//限制三行
    agreeLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    agreeLabel.preferredMaxLayoutWidth = SCREEN_WIDTH -40;
    
    NSString *text = @" 为了您更好地使用越轻盈，请在使用前仔细阅读《用户服务协议》和《隐私协议》";
    NSMutableAttributedString *attString = [NSMutableAttributedString.alloc initWithString:text];
    [attString yy_setAttribute:NSForegroundColorAttributeName value:HLTextColor1];

    [attString yy_setTextHighlightRange:[text rangeOfString:@"《用户服务协议》"] color:HLMainColor backgroundColor:agreeLabel.backgroundColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [modalViewController hideWithAnimated:YES completion:nil];
        [HLUIHelper h5WithURL:HLH5ProtocolUserUrl controller:[QMUIHelper visibleViewController]];
    }];
    [attString yy_setTextHighlightRange:[text rangeOfString:@"《隐私协议》"] color:HLMainColor backgroundColor:agreeLabel.backgroundColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [modalViewController hideWithAnimated:YES completion:nil];
        [HLUIHelper h5WithURL:HLH5ProtocolPrivacyUrl controller:[QMUIHelper visibleViewController]];
    }];
    
    agreeLabel.attributedText = attString;
    [contentView addSubview:agreeLabel];
    [agreeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(lineView);
        make.top.equalTo(lineView.mas_bottom).offset(16);
    }];
    
    
    UILabel *contentLabel = [[UILabel alloc] qmui_initWithFont:UIFontMake(12) textColor:HLTextColor1];
    contentLabel.numberOfLines = 0;
    contentLabel.qmui_lineHeight = 20;
    contentLabel.text = @"在您使用APP过程中，平台会在您同意请求的前提下，对您的部分信息进行收集和使用。我们会申请设备的相机权限、相册访问权限、位置权限、录音权限等。未经您的同意，我们不会共享或出售您的任何信息，您可以随时变更部分信息，或删除个人账户。";
    [contentView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(agreeLabel.mas_bottom).offset(20);
        make.left.right.equalTo(agreeLabel);
    }];
    
    
    UILabel *tipLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(12) textColor:HLTextColor1];
    tipLabel.text = @"如您同意以上信息，请点击同意按钮，开启新的美食之路。";
    tipLabel.numberOfLines = 0;
    tipLabel.qmui_lineHeight = 18;
    [contentView addSubview:tipLabel];
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentLabel);
        make.top.equalTo(contentLabel.mas_bottom).offset(20);
    }];
    
    QMUIButton *cancelButton = [[QMUIButton alloc] init];
    [cancelButton setTitle:@"不同意" forState:UIControlStateNormal];
    [cancelButton setTitleColor:HLTextColor3 forState:UIControlStateNormal];
    [cancelButton.titleLabel setFont:UIFontMediumMake(15)];
    [cancelButton setBackgroundColor:HLBackgroundColor];
    [contentView addSubview:cancelButton];
    [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(0);
        make.height.mas_equalTo(60);
        make.right.equalTo(contentView.mas_centerX);
    }];
    
    QMUIButton *confirmButton = [[QMUIButton alloc] init];
    [confirmButton setTitle:@"同意并继续" forState:UIControlStateNormal];
    [confirmButton setTitleColor:UIColorWhite forState:UIControlStateNormal];
    [confirmButton.titleLabel setFont:UIFontMediumMake(15)];
    [confirmButton setBackgroundColor:HLMainColor];
    [contentView addSubview:confirmButton];
    [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(60);
        make.left.equalTo(contentView.mas_centerX);
    }];
    
    [confirmButton setQmui_tapBlock:^(__kindof UIControl *sender) {
        [userDefault setBool:YES forKey:HLMustAgreeIdentifier];
        [modalViewController hideWithAnimated:YES completion:nil];
    }];
    
    modalViewController.contentView = contentView;
    [modalViewController showWithAnimated:YES completion:nil];
}


+ (void)showAlertMustAgreeProtocalWithCallback:(HLCommonCallbackBoolBlock)callback
{
    
    QMUIModalPresentationViewController *modalViewController = [[QMUIModalPresentationViewController alloc] init];
    modalViewController.modal = YES;
    
    
    CGFloat width = SCREEN_WIDTH;
    CGFloat height = 410;
    
    modalViewController.contentViewMargins =  UIEdgeInsetsMake(SCREEN_HEIGHT-height, 0, 0, 0);
    
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    contentView.backgroundColor = UIColorWhite;
    contentView.layer.cornerRadius = 20;
    
    
    
    UILabel *titleLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(20) textColor:HLTextColor1];
    titleLabel.text = @"欢迎来到越轻盈！";
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(24);
    }];
    
    UIImageView *iconView = [[UIImageView alloc] initWithImage:UIImageMake(@"must_agree_icon")];
    [contentView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16);
        make.right.mas_equalTo(-12);
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = HLLineColor;
    [contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(iconView.mas_bottom).offset(2);
    }];
        
    YYLabel *agreeLabel = [[YYLabel alloc] init];
    agreeLabel.font = UIFontMediumMake(12);
    agreeLabel.textColor = HLTextColor1;
    agreeLabel.numberOfLines = 3;//限制三行
    agreeLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    agreeLabel.preferredMaxLayoutWidth = SCREEN_WIDTH -40;
    
    NSString *text = @" 为了您更好地使用越轻盈，请在使用前仔细阅读《用户服务协议》和《隐私协议》";
    NSMutableAttributedString *attString = [NSMutableAttributedString.alloc initWithString:text];
    [attString yy_setAttribute:NSForegroundColorAttributeName value:HLTextColor1];

    [attString yy_setTextHighlightRange:[text rangeOfString:@"《用户服务协议》"] color:HLMainColor backgroundColor:agreeLabel.backgroundColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [modalViewController hideWithAnimated:YES completion:nil];
        [HLUIHelper h5WithURL:HLH5ProtocolUserUrl controller:[QMUIHelper visibleViewController]];
    }];
    [attString yy_setTextHighlightRange:[text rangeOfString:@"《隐私协议》"] color:HLMainColor backgroundColor:agreeLabel.backgroundColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [modalViewController hideWithAnimated:YES completion:nil];
        [HLUIHelper h5WithURL:HLH5ProtocolPrivacyUrl controller:[QMUIHelper visibleViewController]];
    }];
    
    agreeLabel.attributedText = attString;
    [contentView addSubview:agreeLabel];
    [agreeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(lineView);
        make.top.equalTo(lineView.mas_bottom).offset(16);
    }];
    
    
    UILabel *contentLabel = [[UILabel alloc] qmui_initWithFont:UIFontMake(12) textColor:HLTextColor1];
    contentLabel.numberOfLines = 0;
    contentLabel.qmui_lineHeight = 20;
    contentLabel.text = @"在您使用APP过程中，平台会在您同意请求的前提下，对您的部分信息进行收集和使用。我们会申请设备的相机权限、相册访问权限、位置权限、录音权限等。未经您的同意，我们不会共享或出售您的任何信息，您可以随时变更部分信息，或删除个人账户。";
    [contentView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(agreeLabel.mas_bottom).offset(20);
        make.left.right.equalTo(agreeLabel);
    }];
    
    
    UILabel *tipLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(12) textColor:HLTextColor1];
    tipLabel.text = @"如您同意以上信息，请点击同意按钮，开启新的美食之路。";
    tipLabel.numberOfLines = 0;
    tipLabel.qmui_lineHeight = 18;
    [contentView addSubview:tipLabel];
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentLabel);
        make.top.equalTo(contentLabel.mas_bottom).offset(20);
    }];
    
    QMUIButton *cancelButton = [[QMUIButton alloc] init];
    [cancelButton setTitle:@"不同意" forState:UIControlStateNormal];
    [cancelButton setTitleColor:HLTextColor3 forState:UIControlStateNormal];
    [cancelButton.titleLabel setFont:UIFontMediumMake(15)];
    [cancelButton setBackgroundColor:HLBackgroundColor];
    [contentView addSubview:cancelButton];
    [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(0);
        make.height.mas_equalTo(66);
        make.right.equalTo(contentView.mas_centerX);
    }];
    
    QMUIButton *confirmButton = [[QMUIButton alloc] init];
    [confirmButton setTitle:@"同意并继续" forState:UIControlStateNormal];
    [confirmButton setTitleColor:UIColorWhite forState:UIControlStateNormal];
    [confirmButton.titleLabel setFont:UIFontMediumMake(15)];
    [confirmButton setBackgroundColor:HLMainColor];
    [contentView addSubview:confirmButton];
    [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(66);
        make.left.equalTo(contentView.mas_centerX);
    }];
    
    [confirmButton setQmui_tapBlock:^(__kindof UIControl *sender) {
        if (callback){
            callback(YES);
        };
        [modalViewController hideWithAnimated:YES completion:nil];
    }];
    
    [cancelButton setQmui_tapBlock:^(__kindof UIControl *sender) {
        if (callback){
            callback(NO);
        };
        [modalViewController hideWithAnimated:YES completion:nil];
    }];
    
    modalViewController.contentView = contentView;
    [modalViewController showWithAnimated:YES completion:nil];
}


@end
